package switchviz.graphic.signal;

import java.util.Iterator;
import java.util.List;

import org.jdom.Element;

public class SignalsConfigurationPersistence 
{
	public static final String SIGNAL = "signal";
	private Element _node = null;
	
	public void setElement(Element node)
	{
		_node = node;
	}
	
	public Element getElement()
	{
		return _node;
	}
	
	public SignalsConfigurationPersistence(Element node)
	{
		this.setElement(node);
	}
	
	public ListSignalElement[] getAllSignalDataModel()
	{
		ListSignalElement[] siglist = null;
		
		if(getElement().getChild(SIGNAL) != null)
		{
			List<?> elementlist = getElement().getChildren(SIGNAL);
			Iterator<?> elementiterator = elementlist.iterator();
			siglist = new ListSignalElement[elementlist.size()];
			int i = 0;
			while(elementiterator.hasNext())
			{
				Element node = (Element)elementiterator.next();
				siglist[i] = new ListSignalElement(((new BasicSignalPersistence(node)).getDataModelFromElement()), node);
				++i;
			}
		}
		return siglist;
	}
	
	public void addSignal(Element signode)
	{
		getElement().addContent(signode);
	}
	
	public Element getNewSignalNode()
	{
		return new Element(SIGNAL);
	}
	
}
